//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "India.h"
using namespace Cephei::QL::Times::Calendars;
#include <gen/QL/Times/Period.h>
#include <gen/QL/Times/Calendar.h>
using namespace Cephei::QL::Times;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Times::Calendars::CIndia::CIndia (Microsoft::FSharp::Core::FSharpOption<QL::Times::Calendars::India::MarketEnum>^ m) : CCalendar(CIndia::typeid)
{
    try
    {
#ifdef HANDLE
        _phIndia = NULL;
#endif
        QuantLib::India::Market _m = 
            (Microsoft::FSharp::Core::FSharpOption<QL::Times::Calendars::India::MarketEnum>::IsSome::get (m) ? (QuantLib::India::Market)m->Value : QuantLib::India::Market::NSE); //10
        _ppIndia = new boost::shared_ptr<QuantLib::India> (new QuantLib::India ( _m ));
        SetCalendar (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppIndia));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::Calendars::CIndia::CIndia (boost::shared_ptr<QuantLib::India>& childNative, Object^ owner) : CCalendar(CIndia::typeid)
{
#ifdef HANDLE
	_phIndia = NULL;
#endif
	_ppIndia = &childNative;
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppIndia));
}
Cephei::QL::Times::Calendars::CIndia::CIndia (QuantLib::India& childNative, Object^ owner) : CCalendar(CIndia::typeid)
{
#ifdef HANDLE
	_phIndia = NULL;
#endif
	_ppIndia = new boost::shared_ptr<QuantLib::India> (&childNative);
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppIndia));
    _IndiaOwner = owner;
    _CalendarOwner = owner;
}

Cephei::QL::Times::Calendars::CIndia::CIndia (CIndia^ copy) : CCalendar(CIndia::typeid)
{
#ifdef HANDLE
	_phIndia = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppIndia = new boost::shared_ptr<QuantLib::India> (copy->GetShared());
        _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppIndia));
    }
}
Cephei::QL::Times::Calendars::CIndia::CIndia (System::Type^ t) : CCalendar(CIndia::typeid)
{
#ifdef HANDLE
	_phIndia = NULL;
#endif
	if (!t->IsSubclassOf(CIndia::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Times::Calendars::CIndia::CIndia (QuantLib::Handle<QuantLib::India>& childNative, Object^ owner)  : CCalendar(CIndia::typeid)
{
	_phIndia = &childNative;
	_ppIndia = &static_cast<boost::shared_ptr<QuantLib::India>>(childNative.currentLink());
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppIndia));
    _IndiaOwner = owner;
}
Cephei::QL::Times::Calendars::CIndia::CIndia (QuantLib::Handle<QuantLib::India> childNative)  : CCalendar(CIndia::typeid)
{
	_phIndia = &childNative;
	_ppIndia = &static_cast<boost::shared_ptr<QuantLib::India>>(childNative.currentLink());
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppIndia));
}
#endif
#ifdef STRUCT
Cephei::QL::Times::Calendars::CIndia::CIndia (QuantLib::India childNative)  : CCalendar(CIndia::typeid)
{
#ifdef HANDLE
	_phIndia = NULL;
#endif
	_ppIndia = new boost::shared_ptr<QuantLib::India> (new QuantLib::India (childNative));
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppIndia));
}
#endif

Cephei::QL::Times::Calendars::CIndia::~CIndia ()
{
    if (_ppIndia != NULL)
    {
	    delete _ppIndia;
        _ppIndia = NULL;
    }
}
Cephei::QL::Times::Calendars::CIndia::!CIndia ()
{
    if (_ppIndia != NULL)
    {
	    delete _ppIndia;
    }
}
QuantLib::India& Cephei::QL::Times::Calendars::CIndia::GetReference ()
{
    if (_ppIndia == NULL) throw gcnew NativeNullException ();
	return **_ppIndia;
}
boost::shared_ptr<QuantLib::India>& Cephei::QL::Times::Calendars::CIndia::GetShared ()
{
    if (_ppIndia == NULL) throw gcnew NativeNullException ();
	return *_ppIndia;
}
QuantLib::India* Cephei::QL::Times::Calendars::CIndia::GetPointer ()
{
    if (_ppIndia == NULL) throw gcnew NativeNullException ();
	return &**_ppIndia;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::India>& Cephei::QL::Times::Calendars::CIndia::GetHandle ()
{
	if (_phIndia == NULL)
	{
		_phIndia = new Handle<QuantLib::India> (*_ppIndia);
	}
	return *_phIndia;
}
#endif
bool Cephei::QL::Times::Calendars::CIndia::HasNative () 
{
	return (_ppIndia != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Times::Calendars::IIndia^ Cephei::QL::Times::Calendars::CIndia_Factory::Create (Microsoft::FSharp::Core::FSharpOption<QL::Times::Calendars::India::MarketEnum>^ m)
{
    return gcnew CIndia ( m);
}
